#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <pthread.h>
#include <thread>

std::string toHex(pthread_t tid)
{
    char buffer[64];
    snprintf(buffer,sizeof(buffer),"0x%lx",tid);
    return buffer;
}

void* routine(void* args)
{
    std::string name = static_cast<const char*>(args);
    while(true)
    {
        std::cout << "我们是新线程,我的名字是: " << name << ", my tid is : " << toHex(pthread_self()) << std::endl;
        sleep(1);
    }
    return 0;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid,nullptr,routine,(void*)"thread-1");

    // std::cout << "new thread id: " << tid << std::endl;
    printf("new thread id: 0x%lx\n",tid);

    while(true)
    {
        std::cout << "我们是main线程..." << " , my tid is : " << toHex(pthread_self()) << std::endl;
        sleep(1);
    }
    return 0;
}



